package com.dbs.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dbs.common.DatabaseContextHolder;
import com.dbs.common.DatabaseType;
import com.dbs.config.DataSourceTest1Properties;
import com.dbs.dao.test1.UserDaoTest1;
import com.dbs.dao.test2.UserDaoTest2;
import com.dbs.po.User;
import com.dbs.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDaoTest1 userDao;
	@Autowired
	private UserDaoTest2 userDaoTest2;
	
	@Override
	public User findUserById() {
		DatabaseContextHolder.setDatabaseType(DatabaseType.local_test2);
		return userDao.findUserById(1l);
		
	}
	
	@Override
	public User findUserById2() {
		return userDao.findUserById(1l);
	}

	@Override
	@Transactional(rollbackFor=Exception.class)
	public boolean updateUserById() {
		int flag=userDao.updateUserById(1l);
		//DatabaseContextHolder.setDatabaseType(DatabaseType.local_test2);
		flag=userDaoTest2.updateUserById(1l);
		int i=1/0;
		return flag>0;
	}


}
